import { request } from './request'

const api = {
  findkey: '/dictionary/find', // 获取单个字典
  findkeys: '/dictionary/findKeys', // 获取多个字典
  findList: '/dictionary/findList', // 字典列表
  upsert: '/dictionary/upsert', // 新增和更新字典
}

export function dictFind(key: string) {
  return request.get(`${api.findkey}/${key}`)
}

export function dictFindKeys(keys: string[]) {
  return request.post(api.findkeys, keys)
}

export interface IPageInfo {
  pageNum: number
  pageSize: number
}
export interface IDictFindListParams {
  conditions: Record<string, unknown>
  fields: Record<string, unknown>
  pageInfo: IPageInfo
  sort: Record<string, unknown>
}

export function dictFindList(params: IDictFindListParams) {
  return request.post(api.findList, params)
}

export interface IDictUpsertParams {
  desc: string
  id?: number
  key: string
  values: Record<string, unknown>[]
}

export function dictUpsert(params: IDictUpsertParams) {
  return request.post(api.upsert, params)
}
